﻿using System.Linq;
using System.Modules.Contracts.DTO;
using System.Reflection;

namespace System.Modules.Extensions
{
    /// <summary>
    /// Assembly Extensions
    /// </summary>
    public static class AssemblyExtensions
    {
        /// <summary>
        /// Get Assembly Details
        /// </summary>
        /// <param name="assembly"></param>
        /// <returns></returns>
        public static AssemblyDetails GetAssemblyDetails(this Assembly assembly)
        {
            var details = new AssemblyDetails();
            var type = details.GetType();
            if (assembly != null)
            {
                type.GetProperties().ToList().ForEach(property => property.SetValue(details, assembly.GetCustomAttributes(property.PropertyType, false).FirstOrDefault(), null));
            }
            return details;
        }
    }
}
